package com.rainng.coursesystem.controller;


import com.rainng.coursesystem.service.BaiduApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api/baidu")
public class BaiduApiController {

    @Autowired
    private BaiduApiService baiduApiService;

    @GetMapping("/call")
    public String callBaiduApi(@RequestParam String userInput) {
        try {
            return baiduApiService.callApi(userInput);
        } catch (IOException e) {
            e.printStackTrace();
            return "Error: " + e.getMessage();
        }
    }
}
